package com.jdk.demo.queue.priorityQueue;

public class PriorityEntity implements Comparable<PriorityEntity> {

    private String data;
    private int priority;

    public PriorityEntity(String data, int priority) {
        this.data = data;
        this.priority=priority;
    }

    public String toString(){
        return "# [data="+data+" priority="+priority+"]";
    }

    //数字小，优先级高
    public int compareTo(PriorityEntity o) {
        return this.priority > o.priority ? 1 : this.priority < o.priority ? -1 : 0;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((data == null) ? 0 : data.hashCode());
		result = prime * result + priority;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PriorityEntity other = (PriorityEntity) obj;
		if (data == null) {
			if (other.data != null)
				return false;
		} else if (!data.equals(other.data))
			return false;
		if (priority != other.priority)
			return false;
		return true;
	}

}
